home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / interapplication comm / coresample / coresample.h < prev    next >
Encoding:
Text File  |  2000-06-23  |  9.2 KB  |  174 lines

  1. /*
  2.     File:        CoreSample.h
  3.  
  4.     Contains:    An application that is Apple Event-aware, Scripting Compatible,        
  5.                 and recordable. It supports the Required and Core Suite of             
  6.                 Apple Events, the Object Model, and the Open Scripting                
  7.                 Architecture.
  8.                                                                                                     
  9.                 The main purpose of this sample code is to demonstrate how to develop an             
  10.                 application that is Apple event-aware, scripting compatible, uses the Object        
  11.                 Support Library, and supports Apple's Open Scripting Architecture.  In                 
  12.                 addition, it has its own 'aete' (Apple Event Terminology Extension) resource        
  13.                 (CoreSampleAETE.r). By    incorporating these technologies into your application,    
  14.                 your application will support Apple's Open Scripting Architecture.                    
  15.                                                                                         
  16.                 The functionality of CoreSample is basic window manipulation. The user may            
  17.                 create, drag, size, zoom, and close windows.  All these actions    may be                
  18.                 performed through Apple events.                                                        
  19.                                                                                             
  20.                 This application is also "factored", which means that user interactions (such        
  21.                 as dragging or sizing a window, selecting a menuitem) are converted into Apple        
  22.                 events which the application sends off to itself, and then is handled by the        
  23.                 corresponding event handler.  Factoring makes it possible to access the appli-        
  24.                 cation's functionality through Apple events. It also makes it easier to record        
  25.                 the user's actions in the form of Apple events.                                        
  26.                                                                                             
  27.                 CoreSample supports the Required and Core suites of events, and the application        
  28.                 and window object classes. One additional property has been added to the window     
  29.                 class, and that is its position, the top left-hand coordinates of the window.        
  30.                 Some events only apply to the window class, such as Create, Move, Clone, and         
  31.                 Set Data (application properties are not modifiable, except for pClipboard,         
  32.                 which I do not support).  Currently, CoreSample supports the Simple Grammar,        
  33.                 as defined in the "Object Support Library Developer Note".                            
  34.                                                                                             
  35.                 The properties you may access with the Get Data Apple event are as follows:            
  36.                     Application - Best Type, Default Type, Class, Name, IsFrontProcess, Version        
  37.                     Window - Best Type, Default Type, Bounds, Class, Index, Name, Position,            
  38.                      Closeable, Titled, Resizable, Zoomable, Floating, Modal, Zoomed,        
  39.                      and Visible.                                                            
  40.                 The properties you may set with the Set Data Apple event are as follows:            
  41.                     Window - Bounds, Index, Zoomed, Name, Position, and Visible.                    
  42.                                                                                             
  43.                 When you create a new element, you may pass it initial data values. This            
  44.                 application will create the    new element accordingly if either or both of the        
  45.                 initial data parameters exist. In addition, with CoreSample, you may create or        
  46.                 move a window without passing it an insertion location record. By default, a        
  47.                 window will be created/moved to the frontmost position.                                
  48.                                                                                             
  49.                 (NOTE: Some portions of this code are derived from TESample, a                        
  50.                 sample application provided by Apple Developer Technical Support.)                    
  51.  
  52.     Written by:    Sue Dumont     
  53.  
  54.     Copyright:    Copyright © 1992-1999 by Apple Computer, Inc., All Rights Reserved.
  55.  
  56.                 You may incorporate this Apple sample source code into your program(s) without
  57.                 restriction. This Apple sample source code has been provided "AS IS" and the
  58.                 responsibility for its operation is yours. You are not permitted to redistribute
  59.                 this Apple sample source code as "Apple sample source code" after having made
  60.                 changes. If you're going to re-distribute the source, we require that you make
  61.                 it clear in the source that the code was descended from Apple sample source
  62.                 code, but that you've made changes.
  63.  
  64.     Change History (most recent first):
  65.                 7/21/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  66.                 12/1/93        <dan>            added PowerPC support - will run native on PowerPC if     
  67.                                             compiled on PowerPC system.    These changes are denoted        
  68.                                             by [pwpc].
  69.                 6/22/93      <doo>            converted files to run in the Think C 6.0 environment    
  70.                                             Fixed incorrect comparison of rects and windowlist problems    
  71.                                             associated with the Think compiler.    
  72.                 4/02.93      <smd>            added GetWindowBounds routine to calculate the correct    
  73.                                             bounds when the bounds accessed from the content region is    
  74.                                             invalid (such as when the application is hidden).                
  75.                                         -    cleaned up the aete.
  76.                 10/01/92      <smd>             Added pVersion to application and now set the port before    
  77.                                             setting the pPosition property.        
  78.                 07/19/92      <smd>            Fixed bug where the Move event was not recording the    
  79.                                             correct window being moved when the data was being passed    
  80.                                             by index rather than by name.    
  81.                 04/30/92      <smd>            Check if replacing the same window in HandleMove    
  82.                                             (i.e., "move window 2 to window 2"). If so, do nothing.        
  83.                 06/25/92      <smd>            Changed FindRelativeWindow to return the windowPtr of the        
  84.                                             window being replaced rather than closing it. This caused        
  85.                                             an error when trying to replace the same window, in which        
  86.                                             case nothing should happen. (Ex. move window 2 to window 2).
  87.                 04/27/92      <smd>            Fixed bug in DoSetData where data was set to a pointer, and    
  88.                                             then the pointer was diposed of.
  89.                 04/20/92      <smd>             Fixed a bug with setting the visibility property of a window.
  90.                 02/28/92      <smd>            Added coercion routines (thanks Kevin) to clean up code.    
  91.                                             These convert from descs to boolean, long, and pstrings.
  92.                 02/25/92      <smd>            Modified GetWindowWithTitle, GetWidnowWithIndex, and    
  93.                                             GetWindowIndexNum routines to use WindowList so ALL windows        
  94.                                             will be accessed (even invisible ones).                            
  95.                                          -    Changed InitializeDescs to MyInitDescs and DisposeDescs to    
  96.                                             MyDisposeDescs.                                                    
  97.                                          -    Removed the FailIfErr calls from the AE Handlers so that        
  98.                                             they will return the error code rather than dying.
  99.                 02/24/92      <smd>            Now sends a Move event when just making a window active.    
  100.                                             This is done in the DoEvent routine, drag region.
  101.                 02/21/92      <smd>            Fixed bug where the same AEDesc was being passed as source    
  102.                                             and dest to AECoerceDesc().                                        
  103.                                             Send myself a Move event when user clicks in content of a        
  104.                                             window.
  105.                 02/17/92      <smd>            Added InitializeDescs() and DisposeDescs() routines.    
  106.                 02/05/92      <smd>            Handling optional parameters in Create Element event.
  107.                 01/30/92      <smd>            Adding complete support for core suite and properties.
  108.                 01/21/92      <smd>            Positive and negative offset when referencing by index.
  109.                 01/10/92      <smd>            Made insertion location parameter optional in the Create
  110.                                             and Move events, and provided my own default behavior.    
  111.                 01/09/92      <kc>            Quick clean up for Scripting QuickStart.        
  112.                 01/06/92      <kc>            Added code for Count Elements, Do Objects Exist, Move,
  113.                                             and Get Data Size
  114.                 11/91          <smd>            Initial code implementation.                    
  115.  
  116. */
  117.  
  118. #define    pPosition         'ppos'            // Position property code id for window.
  119. #define kAEDontExecute    0x00002000L        // Flag used for smart recording.
  120. #define kCoreSampleID    'smpl'            // suite id code for CoreSample
  121.  
  122. #define    kNameKeyForm        1            // Indicates formName for object specifier.
  123. #define    kIndexKeyForm        2            // Indicates formAbsolutePosition.
  124. #define    kEndOfList            nil            // Nil terminator for variable argument list.
  125.  
  126.  
  127.     //    Menu Items.
  128. #define    mApple                    128            // Apple menu
  129. #define    iAbout                    1
  130. #define    mFile                    129            // File menu
  131. #define    iNew                    1
  132. #define    iClose                    4
  133. #define    iQuit                    8
  134. #define    mEdit                    130            // Edit menu
  135. #define    iUndo                    1
  136. #define    iCut                    3
  137. #define    iCopy                    4
  138. #define    iPaste                    5
  139. #define    iClear                    6
  140.  
  141. #define kDITop                    0x0050        // Disk event dialog
  142. #define kDILeft                    0x0070        // box data.
  143. #define    kMaxStringSize            255            // Max # characters in string.
  144. #define    kMinWinDim                64            // Minimum size of a window.
  145. #define    kSysEnvironsVersion        1            // SysEnvRec version.
  146. #define    kOSEvent                app4Evt        // Event used by MultiFinder.
  147. #define    kSuspendResumeMessage    1            // High byte of suspend/resume event message.
  148. #define    kResumeMask                1            // Bit of message field for resume vs. suspend.
  149. #define    kMouseMovedMessage        0xFA        // High byte of mouse-moved event message.
  150. #define    kNoEvents                0            // No events mask.
  151.  
  152.     //    Min result from the equation: ORD(GetApplLimit) - ORD(ApplicZone)     
  153. #define    kMinHeap                (29 * 1024)    // Min size of memory.
  154.     //    Min result from PurgeSpace when called at initialization time. 
  155. #define    kMinSpace                (20 * 1024)
  156. #define kPrefSize                100            // Preferred heap size.
  157. #define kMinSize                 60            // Minimum heap size.
  158.  
  159.     // The following are indicies into STR# resources.
  160. #define    eWrongMachine            1
  161. #define    eSmallSize                2
  162. #define    eNoMemory                3
  163. #define    eAEError                4
  164.  
  165. #define    rMenuBar                128            // application's menu bar
  166. #define    rAboutAlert                128            // about alert
  167. #define    rUserAlert                129            // user error alert
  168. #define    rDocWindow                128            // application's window
  169. #define    kErrStrings                128            // error string list
  170.  
  171.     // Data used in CoreSample.c
  172. #define    kMaxOpenWindows            45            // Max # windows open.
  173. #define    kMaxStrSize                255            // Max # characters in string.
  174.